﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using MeizuSDK.Drawing;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 图像框控件
    /// </summary>
    public class PictureBox : Control
    {
        #region DllImport
        [DllImport("MZFCWrapper.dll")]
        private static extern IntPtr UiPicture2Ctor();

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiPicture2SetImage(IntPtr pObj, [MarshalAs(UnmanagedType.LPWStr)]string path);

        [DllImport("MZFCWrapper.dll")]
        private static extern int UiPicture2GetPaintMode(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiPicture2SetPaintMode(IntPtr pObj, int nMode);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiPicture2SetEdge_Bottom(IntPtr pObj, int nValue);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiPicture2SetEdge_Left(IntPtr pObj, int nValue);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiPicture2SetEdge_Right(IntPtr pObj, int nValue);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiPicture2SetEdge_Top(IntPtr pObj, int nValue);
        #endregion

        #region 公共属性
        /// <summary>
        /// 获取或设置图像控件显示图像的模式
        /// </summary>
        public PaintMode PaintMode
        {
            get
            {
                int nMode = UiPicture2GetPaintMode(Handle);

                return (PaintMode)nMode;
            }
            set
            {
                int nMode = (int)value;

                UiPicture2SetPaintMode(Handle, nMode);
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造图片框控件实例
        /// </summary>
        public PictureBox()
        {
            Handle = UiPicture2Ctor();
            SetID();
        }
        #endregion

        #region 函数
        /// <summary>
        /// 设置底部边缘
        /// </summary>
        /// <param name="nValue">边沿距离</param>
        public void SetBottomEdge(int nValue)
        {
            UiPicture2SetEdge_Bottom(Handle, nValue);
        }
        /// <summary>
        /// 设置左边边缘
        /// </summary>
        /// <param name="nValue">边沿距离</param>
        public void SetLeftEdge(int nValue)
        {
            UiPicture2SetEdge_Left(Handle, nValue);
        }
        /// <summary>
        /// 设置右边边缘 
        /// </summary>
        /// <param name="nValue">边沿距离</param>
        public void SetRightEdge(int nValue)
        {
            UiPicture2SetEdge_Right(Handle, nValue);
        }
        /// <summary>
        /// 设置顶部边缘
        /// </summary>
        /// <param name="nValue">边沿距离</param>
        public void SetTopEdge(int nValue)
        {
            UiPicture2SetEdge_Top(Handle, nValue);
        }
        /// <summary>
        /// 加载指定路径的图片
        /// </summary>
        /// <param name="path"></param>
        public void LoadFromFile(string path)
        {
            if (File.Exists(path))
            {
                UiPicture2SetImage(Handle, path);
            }
        }
        #endregion
    }
}
